﻿using System;
using System.ServiceModel.Channels;
using System.Xml.Serialization;

namespace Nardax.ServiceModel.Discovery.Bindings
{
    public abstract class SerializableBinding<T> where T : Binding
    {
        [XmlIgnore]
        public T Binding { get; set; }

        [XmlAttribute(BindingSerializer.TypeAttributeName)]
        public string Type
        {
            get { return typeof(T).ToString(); }
            set { }
        }

        [XmlAttribute("CT")]
        public String CloseTimeout
        {
            get { return Binding.CloseTimeout.ToString(); }
            set { Binding.CloseTimeout = TimeSpan.Parse(value); }
        }

        [XmlAttribute("OT")]
        public string OpenTimeout
        {
            get { return Binding.OpenTimeout.ToString(); }
            set { Binding.OpenTimeout = TimeSpan.Parse(value); }
        }

        [XmlAttribute("RT")]
        public string ReceiveTimeout
        {
            get { return Binding.ReceiveTimeout.ToString(); }
            set { Binding.ReceiveTimeout = TimeSpan.Parse(value); }
        }

        [XmlAttribute("ST")]
        public string SendTimeout
        {
            get { return Binding.SendTimeout.ToString(); }
            set { Binding.SendTimeout = TimeSpan.Parse(value); }
        }
    }
}
